package ie.dcu.spca.view.category;

import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;
import ie.dcu.spca.Main;
import ie.dcu.spca.R;
import ie.dcu.spca.data.BasicDataManager;
import ie.dcu.spca.data.CategoryDataManager;
import ie.dcu.spca.view.CRUDDialog;

public class CategoryCRUDDialog extends CRUDDialog {

    private String name;
    private EditText nameET;
    private static CategoryDataManager categoryManager;

    @Override
    protected void addOkButtonClickOpt(View v) {
        categoryManager.create(name);
    }

    @Override
    protected void bindWidgetOnCreate() {
        nameET = ((EditText) findViewById(R.id.nameEditText));
    }

    @Override
    protected void deleteBeanOkButtonClickOpt(DialogInterface dialog) {
        categoryManager.delete(id);
    }

    @Override
    protected String getDeleteDataConfirmTip() {
        return this.getString(R.string.deleteCategoryConfirmTip) + name;
    }

    @Override
    protected boolean initializeValuesFromWidget() {
        name = nameET.getText().toString();
        return true;
    }

    @Override
    protected void setValueFromIntentExtrasOnCreate() {
        categoryManager = Main.dataManager.categoryDataManager();
    }

    @Override
    protected void updateBeanWidgetInitialize() {
        name = bundle.getString(BasicDataManager.NAME);
        nameET.setText(name);
    }

    @Override
    protected void updateOkButtonClickOpt(View v) {
        categoryManager.update(id, name);
    }

}
